package com.hspedu.newData.dmsxl.哈希表;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-06 
 * @Version: 1.0
 */

public class LC2215找出两数组的不同 {

    public List<List<Integer>> findDifference(int[] nums1, int[] nums2) {

        HashSet<Integer> set1 = new HashSet<>();
        HashSet<Integer> set2 = new HashSet<>();

        for (int i = 0; i < nums1.length; i++) {
            set1.add(nums1[i]);
        }
        Set<Integer> p2 = new HashSet<>();
        Set<Integer> p1 = new HashSet<>();
        for (int i = 0; i < nums2.length; i++) {
            set2.add(nums2[i]);
            if (!set1.contains(nums2[i])){
                p2.add(nums2[i]);
            }
        }

        for (int i = 0; i < nums1.length; i++) {
            if (!set2.contains(nums1[i])){
                p1.add(nums1[i]);
            }
        }
        List<List<Integer>> res = new ArrayList<>();

        List<Integer> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();

        for (Integer i : p1) {
            list1.add(i);
        }
        for (Integer i : p2) {
            list2.add(i);
        }

        res.add(list1);
        res.add(list2);
        return res;
    }

    @Test
    public void test() {
        // 测试代码

        findDifference(new int[]{1,2,3},new int[]{2,4,6});
    }
}
